﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for clsCHUYENNGANH
/// </summary>
public class clsCHUYENNGANH
{
	public clsCHUYENNGANH()
	{

    }

    #region Select
    public static DataTable Select()
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        try
        {
            dt = connect.GetSelectCommand("CHUYENNGANH_Select", null);
        }
        catch {
            dt = null;
        }
        return dt;
    }
    public static DataTable GetByF_MACHN(string F_MACHN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { F_MACHN };
        string[] parameters = { "@F_MACHN" };
        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }

        try
        {
            dt = connect.GetSelectCommand("CHUYENNGANH_GetByF_MACHN", para);
        }
        catch
        { }
        return dt;
    }
    public static string GetF_TENCHNByF_MACHN(string F_MACHN)
    {
        string rs = "";
        DataTable dt = new DataTable();
        dt = GetByF_MACHN(F_MACHN);
        if (dt.Rows.Count > 0)
        {
            rs = dt.Rows[0]["F_TENCHN"].ToString();
        }
        return rs;
    }
    #endregion

    #region Insert
    public static string Insert(string machn, string tenchn)
    {
        DatabaseConnect connect = new DatabaseConnect();
        SqlParameter[] para = new SqlParameter[2];
        para[0] = new SqlParameter("@F_MACHN", machn);
        para[1] = new SqlParameter("@F_TENCHN", tenchn);

        try
        {
            connect.ExecuteQuery("CHUYENNGANH_Insert", para);
            return "OK";
        }
        catch
        { 
            return "ERR";
        }
    }
    #endregion

    #region Update
    public static string Update(string machn, string tenchn)
    {
        DatabaseConnect connect = new DatabaseConnect();
        SqlParameter[] para = new SqlParameter[2];
        para[0] = new SqlParameter("@F_MACHN", machn);
        para[1] = new SqlParameter("@F_TENCHN", tenchn);

        try
        {
            connect.ExecuteQuery("CHUYENNGANH_Update", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    #endregion

    #region Delete
    public static string Delete(string machn)
    {
        DatabaseConnect connect = new DatabaseConnect();
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACHN", machn);       
        try
        {
            connect.ExecuteQuery("CHUYENNGANH_Delete", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    #endregion
}